package com.mutual.assistance.auth.config;

import com.mutual.assistance.response.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
import org.springframework.stereotype.Component;

/**
 * @author chenyuxin
 * @version 1.0
 * @description 自定义oauth2异常
 * @date 2023/4/28 9:29
 */

@Slf4j
@Component
public class CustomWebResponseExceptionTranslator implements WebResponseExceptionTranslator {

    @Override
    public ResponseEntity<R<String>> translate(Exception e) {
        log.error("认证服务器异常", e);
        return new ResponseEntity<>(R.fail(HttpStatus.UNAUTHORIZED.value(), e.getMessage()), HttpStatus.UNAUTHORIZED);
    }

}
